package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired(required = false)
    private OrderService orderService;

    @Autowired(required = false)
    private HttpSession session;

    @RequestMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        //1.接收前端传递过来json数据封装到Orders对象
        //2.获取登录用户的id
        Long userId = (Long) session.getAttribute("user");

        //3.调用业务层
        orderService.addOrder(orders,userId);

        //返回
        return R.success("下单成功");
    }
}
